package com.mewp.permissions.system.controller;

import com.mewp.permissions.common.entity.Result;
import com.mewp.permissions.model.vo.LoginVo;
import com.mewp.permissions.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author mewp
 * @version 1.0
 * @date 2023/7/29 12:18
 */
@Api(tags = "首页")
@RestController
@RequestMapping("/admin/system/index")
public class IndexController {
    @Resource
    private SysUserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@Validated @RequestBody LoginVo loginVo) {
        Map<String, Object> map = userService.login(loginVo);
        return Result.ok(map);
    }

    @ApiOperation("用户详情")
    @GetMapping("/info")
    public Result info(HttpServletRequest request) {
        //请求头中的token信息
        String token = request.getHeader("token");
        Map<String, Object> map = userService.getUserInfo(token);
        return Result.ok(map);
    }

    @ApiOperation("退出")
    @PostMapping("/logout")
    public Result logout() {
        return Result.ok();
    }

}
